#!/bin/bash
#SBATCH --spread-job
# Copyright (c) 2021 Presto Labs Pte. Ltd.

if [ -z ${SLURM_JOB_ID} ]; then
  (>&2 echo "ERROR: run this script on slurm.")
  exit 1
fi

set -e 
export PYTHONUNBUFFERED=1
REMOTE_HOME={{remote_home}}
source ${REMOTE_HOME}/miniconda3/etc/profile.d/conda.sh
conda activate ${REMOTE_HOME}/{{coin_env}}

NUM_PARALLEL="$((${SLURM_NTASKS} + 30))"
parallel -j "${NUM_PARALLEL}" --delay 0.1 <<EOF
{% for strategy in strategy_list %}
srun -N1 -n1 -l --exclusive --unbuffered \
  ./pyrunner python/coin/support/proto_log/app/strat_state_anaylyzer.py \
    --slurm_run \
    --trading_date={{trading_date}} \
    --strategy_name={{strategy['name']}} \
    --tmp_dir={{tmp_dir}} \
    {% if log_type is not none -%}
      --log_type={{log_type}} \
    {%- else -%}
      \
    {%- endif %}
{% endfor %}
EOF
